package tech.yunland.shop.web;

import com.moyuer.bsf.common.Pagination;
import com.moyuer.bsf.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.yunland.shop.domain.model.MessSendRecord;
import tech.yunland.shop.domain.service.MessSendRecordService;

import java.util.List;

/**
 * 微信消息记录
 *
 * @author 文卡<wkwenka@gmail.com>  on 17-3-4.
 */
@RestController
@RequestMapping("/mess_send_record")
public class MessSendRecordController extends BaseController {

    @Autowired
    private MessSendRecordService messSendRecordService;

    /**
     * 获取消息记录
     * /mess_send_record/
     *
     * @param param    参数
     * @param organIds 组织
     * @param states   状态
     * @param page     当前页
     * @param rows     每页展示的行数
     * @return
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public Pagination getRecordList(@RequestParam(required = false) String param,
                                    @RequestParam(required = false) List<String> organIds,
                                    @RequestParam(required = false) List<Integer> states,
                                    @RequestParam(required = false) Integer page,
                                    @RequestParam(required = false) Integer rows) {
        Pagination pagination = new Pagination(page, rows);
        Integer startIdx = pagination.getStartIdx();

        if (organIds == null) {
            organIds = this.organIds;
        }

        pagination.setCount(messSendRecordService.getRecordListSize(param, organIds, states));
        pagination.setRecords(messSendRecordService.getRecordList(param, organIds, states, startIdx, rows));
        return pagination;
    }
    /**
     * 保存
     * JSON类型：
     * {
     * "title":"标题",
     * "content_source_url":"http://mytest/",
     * "content":"内容",
     * "digest":"图文消息描述",
     * "show_cover_pic":"显示封面"
     * }
     *
     * @param messSendRecord
     */
/*
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public void save(@RequestBody MessSendRecord messSendRecord) {

        messSendRecordService.saveSendInfo(messSendRecord.getTitle(),
                messSendRecord.getContent_source_url(),
                messSendRecord.getContent(),
                messSendRecord.getDigest(),
                messSendRecord.getShow_cover_pic());
    }*/

    /**
     * 查看消息记录详情
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public MessSendRecord getRecordInfo(@PathVariable String id) {
        MessSendRecord infoById = messSendRecordService.getInfoById(id);
        return infoById;
    }

    /**
     * 删除记录
     *
     * @param id
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.DELETE)
    public void delRedord(@PathVariable String id) {
        messSendRecordService.delRecord(id);
    }

}
